<template>
    <div>
        <div class="user-left">
            <div class="avatar" @click="goUser">
                <img
                    class="img"
                    :src="
                        avatar
                            ? avatar
                            : 'https://api.xiaozhucaishui.com/assets/img/avatar.png'
                    "
                    alt=""
                />
                <img
                    v-if="showV"
                    class="v"
                    src="~/assets/images/csjh/V.png"
                    alt=""
                />
            </div>
            <div class="user-info">
                <div class="user-name-time">
                    <div class="name">
                        {{ senderUserID ? senderUserID : "小竹用户" }}
                    </div>
                    <div class="time">{{ timestamp }}</div>
                </div>
                <div
                    v-if="type == 1"
                    v-html="wrapLinksWithAnchorTags(message)"
                    class="user-news"
                ></div>
                <div v-else class="user-news">
                    <img
                        v-if="type == 11"
                        :src="message"
                        alt=""
                        @click="previewImg([message])"
                    />
                    <img
                        v-if="type == 111"
                        :src="message"
                        alt=""
                        class="emoticon"
                    />
                </div>
            </div>
        </div>
        <div v-if="quoteMsg" class="quote-msg">
            {{ quoteMsg.nickname }}：{{ quoteMsg.message }}
        </div>
    </div>
</template>

<script>
import { wrapLinksWithAnchorTags } from "@/assets/utils/utils.js";
export default {
    name: "chatList",
    props: {
        avatar: {
            type: String | Number,
            default: "https://api.xiaozhucaishui.com/assets/img/avatar.png",
        },
        senderUserID: {
            type: String | Number,
            default: "",
        },
        timestamp: {
            type: String | Number,
            default: "",
        },
        message: {
            type: String | Number,
            default: "",
        },
        type: {
            type: Number | String,
            default: 1,
        },
        UserID: {
            type: Number | String,
            default: "",
        },
        showV: {
            type: Boolean,
            default: false,
        },
        quoteMsg: {
            type: Object,
            default: null,
        },
        receiptStatus: {
            type: Number | String,
            default: 1,
        },
    },
    data() {
        return {
            wrapLinksWithAnchorTags: wrapLinksWithAnchorTags,
        };
    },
    mounted() {
        // 滚动到聊天列表底部
        // this.scrollBottom();
    },
    methods: {
        previewImg(imgs) {
            this.$emit("previewImg", imgs);
        },
        goUser() {
            this.$router.push({
                path: "/cswd/user/" + this.UserID,
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.user-left,
.user-right {
    margin-top: 30px;
    display: flex;
}

.user-left {
    align-items: flex-start;
    justify-content: flex-start;
    .avatar {
        width: 60px;
        height: 60px;
        position: relative;
        cursor: pointer;
        .img {
            width: 100%;
            height: 100%;
            overflow: hidden;
            border-radius: 60px;
            object-fit: cover;
        }

        .v {
            position: absolute;
            width: 17px;
            height: 17px;
            right: -1px;
            bottom: -2px;
        }
    }
    .user-info {
        margin-left: 16px;
    }
    .user-name-time {
        justify-content: flex-start;
    }
    .user-news {
        white-space: pre-line;
        display: inline-block;
        background: #f4f4f4;
        border-radius: 4px;
        padding: 11px 21px;
        font-size: 14px;
        color: #333333;
        max-width: 420px;
        position: relative;
        word-wrap: break-word;
        &::before {
            content: "";
            width: 0px;
            height: 0px;
            border: 5px solid transparent;
            border-right-color: #f4f4f4;
            border-right-width: 8px;
            position: absolute;
            left: -12px;
            top: 15px;
        }
        &::v-deep a {
            text-decoration: underline !important;
            color: #2440b3 !important;
        }
        img {
            max-width: 240px;
            width: auto;
            max-height: 180px;
            object-fit: contain;
            cursor: pointer;
        }

        .emoticon {
            max-width: 168px;
            max-height: 126px;
        }
    }
}

.user-name-time {
    padding-bottom: 10px;
    display: flex;
    align-items: flex-end;
    .name {
        font-size: 16px;
        color: #333333;
    }
    .time {
        font-size: 12px;
        padding: 0 7px;
        font-weight: 300;
        color: #666666;
    }
}

.quote-msg {
    padding-right: 76px;
    background-color: #e8e8e8;
    color: #99999c;
    padding: 4px 6px;
    border-radius: 4px;
    display: inline-block;
    font-size: 12px;
    margin-left: 76px;
    margin-top: 7px;
    max-width: 400px;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 20px;
}
</style>
